package com.wdc.queue;


import java.util.Collection;
import java.util.Iterator;
import java.util.Queue;
//用链表来实现队列 ，单向环形待哨兵方式来实现队列
public class LinkedLIstQueue<E> implements Queue<E> ,Iterable<E>  {


    //节点类
    private static class Node<E>{
        Node<E> next;
        E values;

        public Node(E values, Node<E> next) {
            this.next = next;
            this.values = values;
        }
    }
    Node<E> head = new Node<>(null,null);
    Node<E> tail = head;

    public LinkedLIstQueue() {
        tail.next = head;
    }

    @Override
    public boolean add(E Value) {

        return true;
    }

    @Override
    public boolean remove(Object o) {
        return false;
    }

    @Override
    public boolean containsAll(Collection<?> c) {
        return false;
    }

    @Override
    public boolean addAll(Collection<? extends E> c) {
        return false;
    }

    @Override
    public boolean removeAll(Collection<?> c) {
        return false;
    }

    @Override
    public boolean retainAll(Collection<?> c) {
        return false;
    }

    @Override
    public void clear() {

    }

    @Override
    public boolean offer(E Value) {

        //新结点的尾巴要指向头部
        Node<E> newNode =  new Node<>(Value, head);
        tail.next = newNode;
        tail = newNode;



        return true;
    }

    @Override
    public E remove() {
        return null;
    }

    @Override
    public E poll() {
        return null;
    }

    @Override
    public E element() {
        return null;
    }

    @Override
    public E peek() {
        return null;
    }

    @Override
    public int size() {
        return 0;
    }

    @Override
    public boolean isEmpty() {
        return false;
    }

    @Override
    public boolean contains(Object o) {
        return false;
    }

    @Override
    public Iterator<E> iterator() {

        return new Iterator<E>() {
            Node<E> p = head.next;
            @Override
            public boolean hasNext() {

                return p != head;
            }

            @Override
            public E next() {
                System.out.println(p.values);
                E value = p.values;
                p = p.next;

                return value;
            }
        };
    }

    @Override
    public Object[] toArray() {
        return new Object[0];
    }

    @Override
    public <T> T[] toArray(T[] a) {
        return null;
    }

    public static void main(String[] args) {
        LinkedLIstQueue<Integer> queue = new LinkedLIstQueue<>();
        queue.offer(1);
        queue.offer(2);
        queue.offer(3);
        queue.offer(4);
        queue.offer(5);

        queue.iterator();
    }
}
